package com.yeskery.nut.web.demo.config;

import com.yeskery.nut.annotation.bean.Bean;
import com.yeskery.nut.annotation.bean.Configuration;
import com.yeskery.nut.annotation.condition.ConditionalOnProperty;
import com.yeskery.nut.extend.openapi.OpenApi3Metadata;
import com.yeskery.nut.extend.openapi.OpenApi3Plugin;

import java.util.Collections;

/**
 * OpenApi配置
 * @author sprout
 * @version 1.0
 * @date 2023-09-25 22:49
 */
@Configuration
public class OpenApiConfig {

    @Bean
    @ConditionalOnProperty(value = "openapi3.enable", havingValue = "true", matchIfMissing = true)
    public OpenApi3Metadata openApi3Metadata() {
        OpenApi3Metadata openApi3Metadata = new OpenApi3Metadata();
        openApi3Metadata.setTitle("Nut Web Demo");
        openApi3Metadata.setLicenseName("MIT");
        openApi3Metadata.setLicenseUrl("http://opensource.org/licenses/MIT");
        openApi3Metadata.setTermsOfService("https://gitee.com/yeskery/nut-web-demo");
        openApi3Metadata.setExternalDocsDescription("Git Hub Address");
        openApi3Metadata.setExternalDocsUrl("https://gitee.com/yeskery/nut-web-demo");
        openApi3Metadata.setServerUrls(Collections.singletonList("http://127.0.0.1"));
        return openApi3Metadata;
    }

    @Bean
    @ConditionalOnProperty(value = "openapi3.enable", havingValue = "true", matchIfMissing = true)
    public OpenApi3Plugin openApi3Plugin() {
        return new OpenApi3Plugin();
    }
}
